package com.qishenyuan.competition.controller;

import com.qishenyuan.competition.common.Response;
import com.qishenyuan.competition.constant.SearchType;
import com.qishenyuan.competition.dto.SearchReq;
import com.qishenyuan.competition.service.CompetitionService;
import com.qishenyuan.competition.service.FindJobService;
import com.qishenyuan.competition.service.JobRecommendationService;
import com.qishenyuan.competition.service.TeamupService;
import com.qishenyuan.competition.vo.CompetitionBriefResp;
import com.qishenyuan.competition.vo.FindJobBriefResp;
import com.qishenyuan.competition.vo.JobRecommendationBriefResp;
import com.qishenyuan.competition.vo.TeamUpBriefResp;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Jacky
 * @since 2025-04-03
 */
@RestController
@RequestMapping("/search")
public class GlobalSearchController {

    @Resource
    private CompetitionService competitionService;

    @Resource
    private TeamupService teamupService;

    @Resource
    private JobRecommendationService jobRecommendationService;

    @Resource
    private FindJobService findJobService;

    @RequestMapping("/globalSearch")
    public Response<?> globalSearch(@RequestBody @Valid SearchReq searchReq){
        if(searchReq.getType().equals(SearchType.COMPETITION)){
            List<CompetitionBriefResp> competitionBriefRespList = competitionService.searchCompetition(searchReq.getKey());
            return Response.ok(competitionBriefRespList);
        }else if(searchReq.getType().equals(SearchType.TEAM_UP)){
            List<TeamUpBriefResp> teamUpBriefRespList = teamupService.searchTeamUp(searchReq.getKey());
            return Response.ok(teamUpBriefRespList);
        }else if(searchReq.getType().equals(SearchType.JOB_RECOMMENDATION)){
            List<JobRecommendationBriefResp> jobRecommendationBriefRespList = jobRecommendationService.searchJobRecommendation(searchReq.getKey());
            return Response.ok(jobRecommendationBriefRespList);
        }else if(searchReq.getType().equals(SearchType.FIND_JOB)){
            List<FindJobBriefResp> findJobBriefRespList = findJobService.searchFindJob(searchReq.getKey());
            return Response.ok(findJobBriefRespList);
        }else {
            return Response.failed("invalid type");
        }
    }
}
